<?php
class m_public_function extends CI_Model {
	
	function _menu(){
		$sql = "SELECT  child.menus_id , child.menus_label,  child.menus_param, child.menus_url , child.menus_icon , parent.menus_label as parent_label , parent.menus_icon as parent_icon
	FROM s_menus child
	LEFT JOIN s_menus parent ON parent.menus_id = child.menus_parent
	WHERE parent.menus_label is not null
	and child.menus_active = '1' ORDER BY parent.menus_seq,  child.menus_seq ";
		$query = $this->db->query($sql);
		$result = array();
		foreach($query->result() as $row){
			$result[$row->parent_label][] = $row;
		}
		return $result;
	}
	
    function antrian($id = null){
          $sql = "SELECT 
                    pengunjung_nomor , pengunjung_seq , pengunjung_panggilanke, pengunjung_loketnomor
                FROM
                    t_pengunjung
                WHERE 
                    DATE(t_pengunjung.pengunjung_panggil) = DATE(now())
                AND 
                    t_pengunjung.pengunjung_status = 2 ";
            if($id != null){
                $sql .= "AND pengunjung_id = ".$id." ";
            }        
            $sql .= " ORDER BY t_pengunjung.pengunjung_panggil DESC ";
            $query = $this->db->query($sql);
        
             if ($query->num_rows() > 0){
                 $row = $query->row();
                return $row;
            }else{
                return "-";
            }  
        }
	
    function all_antrian(){
          $sql = "SELECT 
                    * 
                FROM 
                    m_loket
                LEFT JOIN 
                    t_pengunjung
                ON m_loket.loket_id = t_pengunjung.m_loket_id
                WHERE 
                    DATE(t_pengunjung.pengunjung_panggil) = DATE(now())
                AND 
                    t_pengunjung.pengunjung_status != 1
                ORDER BY t_pengunjung.pengunjung_panggil DESC
                LIMIT 0, 10
                ";
            $query = $this->db->query($sql);
            return $query->result();
        }
    
	/* all data */
	
	function _loket(){
		$sql = "SELECT loket_id, loket_nama, loket_kode FROM m_loket WHERE loket_active = 1 ";
		
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
    function getfilename($text){
        $data = array(
            "suara_text" => $text
        );
        $this->db->where($data);
        $query = $this->db->get("m_suara");
        $suara_file = $query->row("suara_file");
        return $suara_file;
    }
	
}